package struct
{
	/**
	 *链表 
	 * @author 张进辉
	 * 
	 */	
	public class WList
	{
		/**前结点*/
		public var headNode:WList;
		/**后节点*/
		public var nextNode:WList;
		
		/**链表数据*/
		public var data:Object;
		
		private var _length:int;
		private var _index:int;
		private var _root:WList;
		private var _end:WList;
		
		public function WList(nextNode:Object=null)
		{
		}
		
		/**长度*/
		public function get length():int
		{
			return _length;
		}

		public function set length(value:int):void
		{
			_length = value;
		}

		/**索引*/
		public function get index():int
		{
			return _index;
		}
		/**根*/
		public function get root():WList
		{
			return _root;
		}
		
		
//---------------------------------------------------Method---------------------------------------------		
		/**遍历
		 * @param callback: Queue参数 返回Boolean型数据，如果返回值为true则终止遍历，否则继续遍历*/
		public function forEach(callback:Function):void
		{
			if(enabled)
			{
				var _return:Boolean;
				var _curNode:WList = _root;
				while(_curNode.nextNode && !_return)
				{
					_return = callback(_curNode);
					_curNode = _curNode.nextNode;
				}
			}
		}
		
		public function getNode(index:int):WList
		{
			return null;
		}
		
		public function push(node:WList):WList
		{
			_end.nextNode = node;
			node.headNode = _end;
			_end = node;
			return node;
		}
		
		
		
		
		
		
		
		
		
		
		
		
		
		/**根节点检查*/
		private function get enabled():Boolean
		{
			if(_root)
				return true;
			else
			{
				throw new Error("无效的链表节点");
			}
		}
		
		
	}
}